packs = c('dplyr', 'tmap', 'countrycode')
lapply(packs, require, character.only = T)

data("World") 
world_map = World %>% 
  mutate(ccode = countrycode(iso_a3, 'iso3c', 'iso3n'))

data_list = read.csv('data/map_data.csv', header = T) %>% 
  mutate(HL = as.numeric(is.na(HL) == F, 1, 0), 
         ccode = countrycode(COUNTRY, 'country.name', 'iso3n'),
         ccode = ifelse(COUNTRY == 'Northern Ireland', 372,  ccode)
         )

world_map = left_join(world_map, data_list, by = 'ccode') %>%  
  filter(continent != 'Antarctica') %>% 
  mutate(
         HL = ifelse(HL == 1, 'Yes', HL), 
         HL = ifelse(HL == 0, 'No', HL)
         )
world_map$HL[is.na(world_map$HL)] = "NA" 

tj_world_map = tm_shape(world_map) + tm_fill('HL',
                              title  = 'TJ Trials \nAfter Dictatorship?', 
                              palette = c('white', 'grey', 'black')) + 
  tm_shape(world_map) + tm_borders(lwd = .2)
tmap_save(tj_world_map, 'fig-out/tj_world_map.pdf')
